Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
Which one is appropriate? Form "onsubmit"in HTML?

I'm quite new at JS. I'm not exactly getting what's the difference between <form onsubmit="return func()"> and <form onsubmit="func()"> . Both the cases are doing the same thing. What is the job of return & when do we need that?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Here is more explanation on the issue.

TL;DR: If you use return and func() returns false, the form will not be submitted. Without return, it will run the function and submit the form regardless of the return value of func().

about 4 years ago · Juan Pablo Isaza Relatório

0

You are better off to have something like this

<form id="submit-btn">

Then for the javascript

document.getElementById("submit-btn").addEventListener("click", func);

function func() {
//Stuff Here
}

It is just cleaner, but as for your question. Really they do perform the same thing. It just depends if the output of your function is a boolean value (true or false) if you type return func() and it is a false value then the form will not submit. If you type func() then no matter the output the form will be submitted.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda